<template>
  <div class="GreetingCardPage">
    <HomePage v-if="pageName === 'HomePage'"></HomePage>
    <MinePage v-if="pageName === 'MinePage'"></MinePage>
    <div v-if="pageName === 'turnTablePage'">
      <img @click="pageSwich(0)" class="subPage1" src="./img/h11.png" alt="" />
      <turnTable :gameObj="gameObj"></turnTable>
    </div>
    <TabBar ref="tabBar" :tabBarShow="tabBarShow"></TabBar>
    <wxCode ref="wxCode"></wxCode>
    <div class="pageLoad" v-if="pageLoad">
      <div class="pageLoad1">
        <u-loading-icon size="50"></u-loading-icon>
        <p>页面加载中</p>
      </div>
    </div>
    <div class="pageLoad" v-if="pageLoadId">
      <div class="pageLoad1">
        <u-loading-icon size="50"></u-loading-icon>
        <p>活动不存在</p>
      </div>
    </div>
  </div>
</template>

<script>
import HomePage from './home.vue'
import MinePage from './mine.vue'
import TabBar from './tabBar.vue'
import wxCode from './wxCode.vue'
import $utils from '../../utils'
import turnTable from '../turnTable1/index.vue'

export default {
  components: {
    HomePage,
    MinePage,
    TabBar,
    wxCode,
    turnTable,
  },
  data() {
    return {
      pageName: '',
      pageLoad: true,
      pageLoadId: false,
      tabBarShow: true,
      gameObj: {},
    }
  },
  created() {
    window.onload = () => {
      this.pageLoad = false
    }
    document.title = '相城支行代发客户感恩有礼'

    let title = '相城支行代发客户感恩有礼 v2021.11.15'
    if (!window.localStorage.APP_NAME) {
      window.localStorage.APP_NAME = title
    } else {
      if (window.localStorage.APP_NAME !== title) {
        window.localStorage.clear()
        setTimeout(() => {
          window.location.reload()
        }, 500)
      }
    }
  },
  mounted() {
    let companyId = $utils.urlQuery('companyId') || window.localStorage.companyId
    if (companyId) {
      this.pageLoadId = false
      window.localStorage.companyId = companyId
      this.$refs.wxCode.wxCodeSet()
    } else {
      this.pageLoadId = true
    }
    this.$api.szklhb.getSign({ url: location.href }).then((res) => {
      this.$refs.wxCode.wxShare(res.data)
    })
  },
  methods: {
    popUpMsg(i) {
      this.gameObj = {
        send: i,
        gameTitle: '相城支行代发客户感恩有礼',
        prizeList: [
          {
            name: '5元立减金',
            bgColor: 'rgb(255, 240, 206)',
            img: require('./img/a14.png'),
          },
          {
            name: '10元立减金',
            bgColor: 'rgb(254, 247, 220)',
            img: require('./img/a14.png'),
          },
          {
            name: '20元立减金',
            bgColor: 'rgb(255, 240, 207)',
            img: require('./img/a14.png'),
          },
          {
            name: '30元立减金',
            bgColor: 'rgb(255, 236, 210)',
            img: require('./img/a14.png'),
          },
          {
            name: '50元立减金',
            bgColor: 'rgb(255, 245, 208)',
            img: require('./img/a14.png'),
          },
        ],
      }
      this.pageSwich(2)
    },
    turnPreFoo() {
      return new Promise((resolve, reject) => {
        this.$api.szklhb
          .getActivityMoney(this.gameObj.send)
          .then((res) => {
            let res1 = res.data && res.data.money
            let numX = 0
            let numY = res1 + '元'
            if (numY) {
              if (numY.includes('5元')) {
                numX = 0
              } else if (numY.includes('10元')) {
                numX = 1
              } else if (numY.includes('20元')) {
                numX = 2
              } else if (numY.includes('30元')) {
                numX = 3
              } else if (numY.includes('50元')) {
                numX = 4
              }
            }
            resolve({
              prizeNo: numX,
              prizeName: res1,
            })
          })
          .catch((err) => {
            reject(err.msg)
          })
      })
    },
    alertOff() {
      this.pageSwichBtn(1)
    },
    pageSwich(i) {
      if (i == 0) {
        this.pageName = 'HomePage'
      } else if (i == 1) {
        this.pageName = 'MinePage'
      } else if (i == 2) {
        this.pageName = 'turnTablePage'
      }
    },
    pageSwichBtn(i) {
      this.$refs.tabBar.tabBtn(i)
    },
  },
}
</script>

<style scoped>
.GreetingCardPage {
  background: #f7f9fb;
  min-height: 100vh;
}
.subPage1 {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  padding: 20rpx;
  width: 60rpx;
  height: 60rpx;
}
.pageLoad {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 600;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.pageLoad1 {
  color: #000;
  font-size: 34rpx;
  background: #fff;
  border-radius: 16px;
  width: 520rpx;
  margin: 0 auto;
  padding: 60rpx 30rpx;
}
</style>
